package de.slothsoft.wasbinich.core;

import java.util.Locale;

public class FullPicture implements Cloneable {

    public Long id;
    public String section;
    public String bigPicture;
    public String correctAnswers_de;
    public String description_de;
    public String correctAnswers_en;
    public String description_en;

    public FullPicture() {
	super();
    }

    public FullPicture(Long id, String section, String bigPicture, String correctAnswers_en, String description_en,
	    String correctAnswers_de, String description_de) {
	this.id = id;
	this.section = section;
	this.bigPicture = bigPicture;
	this.correctAnswers_de = correctAnswers_de;
	this.description_de = description_de;
	this.correctAnswers_en = correctAnswers_en;
	this.description_en = description_en;
    }

    public String getCorrectAnswers(Locale locale) {
	if (locale != null && locale.getLanguage().equals("de"))
	    return this.correctAnswers_de;
	return this.correctAnswers_en;
    }

    public void setCorrectAnswers(Locale locale, String correctAnswers) {
	if (locale != null && locale.getLanguage().equals("de")) {
	    this.correctAnswers_de = correctAnswers;
	} else {
	    this.correctAnswers_en = correctAnswers;
	}
    }

    public String getDescription(Locale locale) {
	if (locale != null && locale.getLanguage().equals("de"))
	    return this.description_de;
	return this.description_en;
    }

    public void setDescription(Locale locale, String description) {
	if (locale != null && locale.getLanguage().equals("de")) {
	    this.description_de = description;
	} else {
	    this.description_en = description;
	}
    }

    @Override
    public String toString() {
	return convertToString(getCorrectAnswers(Locale.getDefault()), getDescription(Locale.getDefault()));
    }

    private static String convertToString(String correctAnswers, String description) {
	return correctAnswers == null ? description : correctAnswers.split(",")[0]; //$NON-NLS-1$
    }

    @Override
    public FullPicture clone() {
	try {
	    return (FullPicture) super.clone();
	} catch (CloneNotSupportedException e) {
	    throw new InternalError(e.getMessage());
	}
    }
}
